package severlet;


import bean.Student;
import dao.StudentDao;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet(name = "studentupdate",value = "/studentupdate")
public class StudentUpdate extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        super.doGet(req, resp);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.setCharacterEncoding("UTF-8");
        String studentid = req.getParameter("studentid");
        String password = req.getParameter("password");

        resp.setCharacterEncoding("UTF-8");

        Student stu=new Student();
        stu.setStudentid(studentid);
        stu.setPassword(password);

        StudentDao studentDao=new StudentDao();
        try {
            studentDao.updateSQB(stu);
            System.out.println("修改成功");
            resp.setContentType("text/html;charset=UTF-8");
            resp.getWriter().println("修改成功");
            req.getRequestDispatcher("student_information.jsp").forward(req,resp);

        }catch (Exception e){
            e.printStackTrace();
        }
    }
}
